// 需求：将关于token的操作封装起来 这样将来更好维护
// 1.建立localstorag文件夹
// 2.然后分别引入

import { getUserInfo } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/localstorage'
export default {
  namespaced: true,
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    removeToken(state) {
      state.token = {}
      removeToken()
    },
    setUserInfo(state, info) {
      state.userInfo = info
    }
  },
  actions: {
    async  getUserInfo(contxet) {
      const res = await getUserInfo()
      contxet.commit('setUserInfo', res.data)
    }
  }
}
